Skip to content

Add support for single line statement (if .... then ... [else ...])#12

Merged
verhas merged 3 commits intoverhas:masterfrom
PetrPytelka:single_line_if_statement
Jan 7, 2020
Merged

Add support for single line statement (if .... then ... [else ...])#12
verhas merged 3 commits intoverhas:masterfrom
PetrPytelka:single_line_if_statement

Conversation

@PetrPytelka
Copy link
Copy Markdown
Contributor

Add support for single line statement: if .... then ... [else ...]

See https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-else-statement

@verhas verhas self-requested a review December 24, 2019 13:57
Copy link
Copy Markdown
Owner

@verhas verhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments and amend the code appropriately. They are mainly small things but there is one coding that is significant. Please refactor that method.

Comment thread src/main/java/com/scriptbasic/syntax/BasicSyntaxAnalyzer.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/BasicSyntaxAnalyzer.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/BasicSyntaxAnalyzer.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/BasicSyntaxAnalyzer.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/commands/AbstractCommandAnalyzerIfKind.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerElseIf.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerEndIf.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerIf.java Outdated
@@ -0,0 +1,8 @@
'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need much more complex test cases, like

if true then if true then print "a" else print "b" else print "c"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single-line 'IF' statement is very dangerous because it does not address properly the dangling ELSE problem. There can be many different cases. One command between the 'THEN' and 'ELSE', many commands, empty commands.

IF x THEN a=1 :ELSE: IF y THEN: a=2 ELSE: a=3

This is the main reason that one line IF was not implemented in ScriptBasic. There was no aim to be compatible with RealBASIC or any other basic.

I accept compatibility with any BASIC as that increases usability and after all the ultimate goal is that ppl use the program. Still it feels a bit itchy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested more complex single-line 'IF' statements and fixed one more issue. There are two tests (TestIf3.bas and TestIf4.bas) to verify these cases. I tested same IF statements in Visual Basic with same results.

@PetrPytelka
Copy link
Copy Markdown
Contributor Author

I will prepare a few smaller pull requests as preparation for this one.

@verhas
Copy link
Copy Markdown
Owner

verhas commented Dec 31, 2019

Please make the modifications and resolve the conflict merging the origin master to your branch.

@PetrPytelka PetrPytelka force-pushed the single_line_if_statement branch from d4c7a8a to df3351c Compare January 6, 2020 15:43
Comment thread src/main/java/com/scriptbasic/interfaces/LexicalElement.java Outdated
Comment thread src/main/java/com/scriptbasic/interfaces/NestedStructureHouseKeeper.java Outdated
Comment thread src/main/java/com/scriptbasic/interfaces/NestedStructureHouseKeeper.java Outdated
Comment thread src/main/java/com/scriptbasic/syntax/BasicSyntaxAnalyzer.java Outdated
@PetrPytelka PetrPytelka force-pushed the single_line_if_statement branch from df3351c to 12abe81 Compare January 6, 2020 16:02
@PetrPytelka PetrPytelka force-pushed the single_line_if_statement branch from 12abe81 to 103d740 Compare January 6, 2020 23:07
@PetrPytelka PetrPytelka requested a review from verhas January 6, 2020 23:16
@verhas verhas merged commit 31a0c40 into verhas:master Jan 7, 2020
@PetrPytelka PetrPytelka deleted the single_line_if_statement branch January 8, 2020 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants